extend personLeft.pug

block append pageStyle
	link(href='${relativePath}/static/css/personCenter/supplier.css' type="text/css" rel="stylesheet")
	link(href="${relativePath}/static/css/shopping/foundation.min.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/shopping/foundation-datepicker.css" rel="stylesheet" type="text/css")

block personRight
	div.rightContent.fl
		//- 供应商认证
		div.supplyBox
			//- 头部导航
			ul.topTitle
				li.advDesign.current 广告设计
				li.advInstall 广告安装
				li.carEqui 车辆设备
			div.formContent
				form#design
					div.row
						label 公司名称：
						input.designCompany(type="text" name="designCompany")
					div.row
						label 选择类型：
						ul.xdList.xdListOne.fl
							
					input#btn1(type="button" value="提交").disignBtn

				form#install
					div.row
						label 公司名称：
						input.companyName(type="text" name="companyName")
					div.row
						label 选择类型：
						ul.xdList.xdListTwo.fl
							//- li.current 普通安装
							//- li 高空安装
							//- li 水电安装
					input#btn2(type="button" value="提交").disignBtn
				form#carEqui
					div.row
						label 公司名称：
						input.equiName(type="text" name="equiName")
					div.row
						label 选择车辆：
						ul.xdList.xdListThree.fl
							
					div.row
						label 选择设备：
						ul.xdList.xdListFour.fl
							//- li.current 脚手架
							//- li 桁架
							//- li 吊篮
					//- div.row
					//- 	label &nbsp;&nbsp;&nbsp;车牌号：
					//- 	input.carCode(type="text" name="carCode")
					//- div.row
					//- 	label 车辆所有人：
					//- 	input.carMan.w36(type="text" name="carMan")
					//- div.row
					//- 	label 车辆注册日期：
					//- 	input#timeOne.w36(type="text" placeholder="请选择")
					input#btn3(type="button" value="提交").disignBtn
		


block append pageScript
	script(src="${relativePath}/static/js/jquery.validate.min.js")
	script(src="${relativePath}/static/js/messages_zh.js")


	script.
		$(function(){
			//- 当前选中
			$("#apply").addClass("current").siblings().removeClass("current");
			$(".gysRZ").addClass("current").siblings("a").removeClass("current");
			
			$(".topTitle li").click(function() {
				$(this).addClass("current").siblings().removeClass("current");
				$(".formContent form").hide().eq($(this).index()).show();
			})
			$(".xdList").on("click","li",function() {
				$(this).toggleClass("current");
			})

			//- 广告设计认证
			var validator = $("#design").validate({
				rules: {
					designCompany:{
						required:true
					}
				},
				messages : {
					designCompany:{
						required : "请输入公司名称"
					}
			    },
				errorPlacement: function(error, element) {  
					error.appendTo(element.closest(".row"));
				}
			});
			//- 广告安装认证
			var validator1 = $("#install").validate({
				rules: {
					companyName:{
						required:true
					}
				},
				messages : {
					companyName:{
						required : "请输入公司名称"
					}
			    },
				errorPlacement: function(error, element) {  
					error.appendTo(element.closest(".row"));
				}
			});

			//- 车辆设备认证
			var validator2 = $("#carEqui").validate({
				rules: {
					equiName:{
						required:true
					},
					//- carCode:{
					//- 	required:true
					//- },
					//- carMan:{
					//- 	required:true
					//- }
				},
				messages : {
					equiName:{
						required : "请输入公司名称"
					},
					//- carCode:{
					//- 	required : "请输入车牌号"
					//- },
					//- carMan:{
					//- 	required : "请输入车辆所有人"
					//- },
			    },
				errorPlacement: function(error, element) {  
					error.appendTo(element.closest(".row"));
				}
			});

			//- 广告设计列表
			$.post(shopIp+"/user/supplierVerify",{
				userToken:token,
				type:2
			},function(data){
				//console.log(data);
				var comName = data.data.company_name;
				var designList = data.data.categoryType;
				$(".designCompany").val(comName);
				//console.log(designList);
				for(var i=0;i<designList.length;i++) {
					var designJ = designList[i];
					//console.log(designJ);
					
					if(designJ.is_category == 0) {
						var liEle = "<li cate_id="+designJ.id+">"+designJ.name+"</li>";
					}else{
						var liEle = "<li class='current' cate_id="+designJ.id+">"+designJ.name+"</li>";
					}
					//console.log(liEle);
					$(".xdListOne").append(liEle);

				}
			})

			//- 广告安装列表
			$.post(shopIp+"/user/supplierVerify",{
				userToken:token,
				type:3
			},function(data){
				var designList = data.data.categoryType;
				var comName = data.data.company_name;
				$(".companyName").val(comName);
				//console.log(designList);
				for(var i=0;i<designList.length;i++) {
					var designJ = designList[i];
					if(designJ.is_category == 0) {
						var liEle = "<li cate_id="+designJ.id+">"+designJ.name+"</li>";
					}else{
						var liEle = "<li class='current' cate_id="+designJ.id+">"+designJ.name+"</li>";
					}
					$(".xdListTwo").append(liEle);
				}
			})

			//- 车辆租赁列表
			$.post(shopIp+"/user/supplierVerify",{
				userToken:token,
				type:4
			},function(data){
				var designList = data.data.categoryType;
				var comName = data.data.company_name;
				var designList1 = data.data.categoryVehicle;
				console.log(designList1);
				$(".equiName").val(comName);
				//车辆
				for(var i=0;i<designList.length;i++) {
					var designJ = designList[i];
					if(designJ.is_category == 0) {
						var liEle = "<li cate_id="+designJ.id+">"+designJ.name+"</li>";
					}else{
						var liEle = "<li class='current' cate_id="+designJ.id+">"+designJ.name+"</li>";
					}
					$(".xdListThree").append(liEle);
				}
				//设备
				for(var j=0;j<designList1.length;j++) {
					var designJ = designList1[j];
					if(designJ.is_category == 0) {
						var liEle = "<li cate_id="+designJ.id+">"+designJ.name+"</li>";
					}else{
						if(designJ.is_category == 0) {
							var liEle = "<li cate_id="+designJ.id+">"+designJ.name+"</li>";
						}else{
							var liEle = "<li class='current' cate_id="+designJ.id+">"+designJ.name+"</li>";
						}
					}
					$(".xdListFour").append(liEle);
				}
			})


			

			$("#btn1").click(function() {
				if(validator.form()) {
					if($(".xdListOne li.current").length<1) {
						layer.msg("请至少选择一种类型！");
					} else{
						var arr = [];
						$(".xdListOne li").each(function() {
							if($(this).hasClass("current")) {
								arr.push($(this).attr("cate_id"));
							}
						})
						//console.log(arr);
						$.post(shopIp+"/user/submitSupplierVerify",{
							userToken:token,
							type:2,
							company_name:$("#design .designCompany").val(),
							cate_id:arr,
						},function(data) {
							if(data.status == 200) {
								layer.msg(data.msg);
								setTimeout(function() {
									location.reload();
								},2000)
								
							}  else{
								layer.msg(data.msg);
							}
						})
					}
					
				}
			})

			//- 广告安装提交
			$("#btn2").click(function() {
				if(validator1.form()) {
					if($(".xdListTwo li.current").length<1) {
						layer.msg("请至少选择一种类型！");
					} else{
						var companyName = $("#install .companyName").val();
						var arr = [];
						$(".xdListTwo li").each(function() {
							if($(this).hasClass("current")) {
								arr.push($(this).attr("cate_id"));
							}
						})
						//console.log(arr);
						$.post(shopIp+"/user/submitSupplierVerify",{
							userToken:token,
							type:3,
							company_name:companyName,
							cate_id:arr,
						},function(data) {
							if(data.status == 200) {
								layer.msg(data.msg);
								setTimeout(function() {
									location.reload();
								},2000)
								
							}  else{
								layer.msg(data.msg);
							}
						})
					}
					
				}
			})

			//- 车辆设备提交
			$("#btn3").click(function() {
				if(validator2.form()) {
					if($(".xdListThree li.current").length<1 || $(".xdListFour li.current").length<1) {
						layer.msg("请至少选择一种类型！");
					} else{
						var companyName = $("#carEqui .equiName").val();
						var arr = [];
						var arr1 = [];
						$(".xdListThree li").each(function() {
							if($(this).hasClass("current")) {
								arr.push($(this).attr("cate_id"));
							}
						})
						$(".xdListFour li").each(function() {
							if($(this).hasClass("current")) {
								arr.push($(this).attr("cate_id"));
							}
						})
						//console.log(arr);
						$.post(shopIp+"/user/submitSupplierVerify",{
							userToken:token,
							type:4,
							company_name:companyName,
							cate_id:arr,
							categoryVehicle:arr1
						},function(data) {
							if(data.status == 200) {
								layer.msg(data.msg);
								setTimeout(function() {
									location.reload();
								},2000)
								
							}  else{
								layer.msg(data.msg);
							}
						})
					}
					
				}
			})

		})


